package com.xc.controller;

import com.xc.dto.ResultDTO;
import com.xc.entity.UserNavEntity;
import com.xc.entity.UserNavManyEntity;
import com.xc.entity.UserRoleEntity;
import com.xc.service.UserNavService;
import com.xc.service.UserRoleService;
import com.xc.util.Tool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//restful 增加post，修改put，删除delete，查询get
@RestController
@RequestMapping("/xc/userNav")
@Api(tags = "用户导航（权限）管理")
public class UserNavController {
    @Autowired
    private UserNavService userNavService;


    //    @PostMapping()
//    @ApiOperation("用户权限增加")
//    public ResultDTO add(@RequestBody UserNavEntity userNavEntity) {
//
//        return userNavService.add(userNavEntity);
//    }
    @PostMapping()
    @ApiOperation("用户导航（权限）增加")
    public ResultDTO add(@RequestBody List<UserNavManyEntity> list) {

        return userNavService.addMany(list);
    }

    @PutMapping()
    @ApiOperation("用户导航（权限）修改")
    public ResultDTO update(@RequestBody
                                    UserNavEntity userNavEntity) {
        return userNavService.update(userNavEntity);
    }

    @ApiOperation("用户导航（权限）修改状态enable，1表示正常，0表示未达到标准")
    @PutMapping("/enable")
    public ResultDTO updateEnable(UserNavEntity userNavEntity) {
        return userNavService.updateEnable(userNavEntity);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("用户导航权限删除")
    public ResultDTO delete(@PathVariable Integer id) {
        UserNavEntity userNavEntity = new UserNavEntity();
        userNavEntity.setId(id);
        return userNavService.delete(userNavEntity);
    }


    @GetMapping()
    @ApiOperation("用户导航权限查询")
    public ResultDTO findAll(UserNavEntity userNavEntity) {
        userNavEntity.setPage(Tool.strToPage(userNavEntity.getPage() + ""));
        userNavEntity.setLimit(Tool.strToLimit(userNavEntity.getLimit() + ""));
        return userNavService.findAll(userNavEntity);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户权限")
    public ResultDTO findById(@PathVariable Integer id) {

        return userNavService.findById(UserNavEntity.builder().id(id).build());
    }

    @GetMapping("/findByUserId")
    @ApiOperation("根据用户id查询用户权限")
    public ResultDTO findByUserId(UserNavEntity userNavEntity) {

        return userNavService.findByUserId(userNavEntity);
    }

    @GetMapping("/count")
    @ApiOperation("查询总条数")
    public ResultDTO count(UserNavEntity userNavEntity) {
        return userNavService.count(userNavEntity);
    }
}
